Subject: [PATCH] 002
---
Index: pkg/cloudprovider/yandex/routes.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/pkg/cloudprovider/yandex/routes.go b/pkg/cloudprovider/yandex/routes.go
--- a/pkg/cloudprovider/yandex/routes.go	(revision 4355e41b39cb060df9aed3c13f50d2239caa1192)
+++ b/pkg/cloudprovider/yandex/routes.go	(date 1679489714548)
@@ -87,11 +87,22 @@
 	}

 	kubeNodeName := string(route.TargetNode)
-	nextHop, err := yc.getInternalIpByNodeName(kubeNodeName)
+	addresses, err := yc.NodeAddresses(ctx, route.TargetNode)
 	if err != nil {
 		return err
 	}

+	var nextHop string
+	for _, address := range addresses {
+		if address.Type == v1.NodeInternalIP {
+			nextHop = address.Address
+			break
+		}
+	}
+	if len(nextHop) == 0 {
+		return spew.Errorf("could not determine InternalIP from list of IPs for VM %q: %v", route.TargetNode, addresses)
+	}
+
 	newStaticRoutes := filterStaticRoutes(rt.StaticRoutes, routeFilterTerm{
 		termType:        routeFilterAddOrUpdate,
 		nodeName:        kubeNodeName,
@@ -137,25 +148,6 @@
 	return err
 }

-func (yc *Cloud) getInternalIpByNodeName(nodeName string) (string, error) {
-	kubeNode, err := yc.nodeLister.Get(nodeName)
-	if err != nil {
-		return "", err
-	}
-
-	var targetInternalIP string
-	for _, address := range kubeNode.Status.Addresses {
-		if address.Type == v1.NodeInternalIP {
-			targetInternalIP = address.Address
-		}
-	}
-	if len(targetInternalIP) == 0 {
-		return "", fmt.Errorf("no InternalIPs found for Node %q", nodeName)
-	}
-
-	return targetInternalIP, nil
-}
-
 type routeFilterTerm struct {
 	termType        routeFilterTermType
 	nodeName        string
Index: go.mod
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/go.mod b/go.mod
--- a/go.mod	(revision 4355e41b39cb060df9aed3c13f50d2239caa1192)
+++ b/go.mod	(date 1679489725733)
@@ -3,6 +3,7 @@
 go 1.17

 require (
+	github.com/davecgh/go-spew v1.1.1
 	github.com/deckarep/golang-set v1.7.1
 	github.com/golang/protobuf v1.5.2
 	github.com/pkg/errors v0.9.1
@@ -29,7 +30,6 @@
 	github.com/cespare/xxhash/v2 v2.1.1 // indirect
 	github.com/coreos/go-semver v0.3.0 // indirect
 	github.com/coreos/go-systemd/v22 v22.3.2 // indirect
-	github.com/davecgh/go-spew v1.1.1 // indirect
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
 	github.com/emicklei/go-restful v2.9.5+incompatible // indirect
 	github.com/evanphx/json-patch v4.12.0+incompatible // indirect
